package com.mediastory.spsserver.gcm.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.mediastory.spsserver.gcm.dao.GcmDao;
import com.mediastory.spsserver.gcm.domain.Gcm;

/**
 * Gcm DaoImpl
 * @author Jaewon Choi
 *
 */

@Repository
public class GcmDaoImpl extends SqlSessionDaoSupport  implements GcmDao {

	public GcmDaoImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<Gcm> SelectList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer page = (Integer)condition.get("page");
		Integer maxnum = (Integer)condition.get("maxnum");
		
		List<Gcm> result = null;
		if(page != null && maxnum != null){
			RowBounds rb = new RowBounds(page, maxnum);
			result = getSqlSession().selectList("Gcm.selectList", condition, rb);
		}else{
			result = getSqlSession().selectList("Gcm.selectList", condition);
		}
		
		return result;
	}
	
	@Override
	public Integer SelectListTotalCnt(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer result = getSqlSession().selectOne("Gcm.selectListTotalCnt", condition);
		return result;
	}

	@Override
	public Gcm select(Integer id) throws Exception {
		// TODO Auto-generated method stub
		Gcm result = (Gcm)(getSqlSession().selectOne("Gcm.select", id)); 
		return result;
	}
	
	@Override
	public Gcm select(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		Gcm result = (Gcm)(getSqlSession().selectOne("Gcm.select.move", condition)); 
		return result;
	}

	@Override
	public Gcm insert(Gcm gcm) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().insert("Gcm.insert", gcm);
		return gcm;
	}

	@Override
	public Gcm update(Gcm gcm) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("Gcm.update", gcm);
		return gcm;
	}

	@Override
	public int delete(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("Gcm.delete", condition);
		return result;
	}

	@Override
	public List<Map<String, Object>> SelectListData(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		List<Map<String, Object>> result = getSqlSession().selectList("Gcm.selectList.data", condition);
		return result;
	}

	@Override
	public int insertData(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().insert("Gcm.insert.data", condition);
		return result;
	}

	@Override
	public int deleteData(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().delete("Gcm.delete.data", condition);
		return result;
	}

	@Override
	public Object SelectListDevice(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Object result = getSqlSession().selectList("Gcm.selectList.device", condition);
		return result;
	}

	@Override
	public int insertDevice(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().insert("Gcm.insert.device", condition);
		return result;
	}

	@Override
	public int deleteDevice(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().delete("Gcm.delete.device", condition);
		return result;
	}

}